package com.xiangyang.eos

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View

/**
 * Created by haichecker on 2018/3/22.
 */
class EosView(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : View(context, attrs, defStyleAttr) {
    var w = 0f
    var h = 0f


    val leftOrRightOffPre = 0.125f
    //底部百分比
    val bottomTrianglePre = 0.2037f
    //顶部高度
    val topLinePre = 0.2593f

    val topTriangPre = 0.3024f

    var leftOrRightOff : Float = 0.0f
    var bottomTriangleOff : Float = 0.0f
    var topLineOff : Float = 0.0f
    var topTraingOff :Float = 0.0f
    var centerX : Float = 0.0f
    val strokeWidth = 4f

    val ZERO = 0.0f

    override fun onDraw(canvas: Canvas?) {
        w = measuredWidth.toFloat()
        h = measuredHeight.toFloat()

        size()

        val path = Path()


        //把画笔移到中间
        path.moveTo(centerX,ZERO)
        //画左边顶部线条
        path.lineTo(leftOrRightOff,topTraingOff)
        //画左边中部线条
        path.lineTo(ZERO,bottomTriangleOff)
        //画左边底部线条
        path.lineTo(centerX,h)
        //画右边底部线条
        path.lineTo(w,bottomTriangleOff)
        //画右边中部线条
        path.lineTo( w - leftOrRightOff,topTraingOff)
        //画右边顶部线条
        path.lineTo(centerX,ZERO)
        //画顶部竖线
        path.lineTo(centerX,topLineOff)
        //画三角形左边线条
        path.lineTo(ZERO,bottomTriangleOff)

        path.lineTo(w,bottomTriangleOff)
//
        path.lineTo(centerX,topLineOff)

        path.moveTo(leftOrRightOff,topTraingOff)

        path.lineTo(centerX,h)

        path.lineTo(w - leftOrRightOff,topTraingOff)
        val paint = Paint()
        paint.style = Paint.Style.STROKE
        paint.color = Color.WHITE
        paint.strokeWidth = strokeWidth

        //


        canvas!!.drawPath(path,paint)

        super.onDraw(canvas)
    }

    fun size()
    {
        topLineOff = h * topLinePre

        leftOrRightOff = w * leftOrRightOffPre

        bottomTriangleOff = h - (h * bottomTrianglePre)

        topTraingOff = h * topTriangPre

        centerX = w / 2 - (strokeWidth / 2)
    }

}